#include"yu.h"
#include"jiajia_lmcc.h"

int main(int argc, char *argv[]){
    if(argc != 2){
        printf("使用: ./main <jiajia file path>\n", argv[1]);
        return 1;
    }

    int32_t stat = JiaJia_file_open(argv[1]);
    switch(stat){
    case JiaJia_FILE_OPEN_FAIL:
        Yu_exit(0, "文件 %s，无法打开\n", argv[1]);
        break;
    case JiaJia_FILE_OPEN_NOEXIT:
        Yu_exit(0, "文件 %s，不存在或损坏无法打开\n", argv[1]);
        break;
    case JiaJia_FILE_OPEN_NOTYPE:
        Yu_exit(0, "文件 %s，后缀非 .jiajia\n", argv[1]);
        break;
    }

    int16_t w = _JiaJiaLmcc_word_err;
    while((w = JiaJia_next_word()) != _JiaJiaLmcc_word_eof){
        printf("%d:%s,", w, JiaJiaLmcc_encode_str(w));
    }
    printf("\n, w = %d\n", w);

    JiaJia_file_pt jjfile = JiaJia_file_top();
    JiaJia_word_t *jjword = jjfile->word_begin;
    while(jjword != NULL){
        printf("%p, %d, %s\n", jjword, jjword->word, JiaJiaLmcc_encode_str(jjword->word));
        jjword = jjword->next;
    }

    return 0;
}
